import LevelLianXian_1 from "../base/LevelLianXian_1";

const {ccclass, property} = cc._decorator;

@ccclass
export default class LevelLianXian1 extends LevelLianXian_1 {

    @property({type:cc.Node,displayName:"文本"})
    lbNode:cc.Node = null;

    @property({type:cc.Node,displayName:"文字父节点"})
    lbParentNode:cc.Node = null;

    binGoAni(num:number,str:string){
        this.lbParentNode.destroyAllChildren();
        this.lbParentNode.removeAllChildren();
        let length = str.length;
        let isSigle:boolean = length%2 == 0;
        let posXArr:number[] = [];
        let zposXArr:number[] = [];
        let fposYArr:number[] = [];
        for(let i =0;i<Math.floor(length/2);i++){
            let zx:number = 0;
            let fx:number = 0;
            if(isSigle){
                zx = 100*(i+1) - 50;
                fx = -(100*(i+1) - 50);
            }else{
                zx = 100*(i+1);
                fx = -(100*(i+1));
            }
            zposXArr.push(zx);
            fposYArr.push(fx);
        }
        if(isSigle){
            posXArr = posXArr.concat(fposYArr.reverse()).concat(zposXArr);
        }else{
            posXArr = posXArr.concat(fposYArr.reverse());
            posXArr.push(0);
            posXArr = posXArr.concat(zposXArr);
        }

        for(let i =0;i<length;i++){
            let node = cc.instantiate(this.lbNode);
            this.lbParentNode.addChild(node);
            let lb:cc.Label = node.getComponent(cc.Label);
            lb.string = str[i];
            node.setPosition(posXArr[i],1000);
            cc.tween(node).delay(0.1*i).to(0.5,{y:400},{easing:cc.easing.backOut}).start();
        }

    }

}
